import { readRawBody, getQuery, getMethod } from 'h3'

export default defineEventHandler(async (event) => {
  // console.log("event=====", event)
  const { app } = useRuntimeConfig()

  // const res = await useFetchData('/xxx/xxx/xxx', {
  //     method,
  //     baseURL: event.context.baseUrl,
  //     headers: event.context.headers,
  //     params: getQuery(event),
  //     body
  // })

  // console.log('useFetchData=====', useFetchData)

  // const res = await $fetch('/api/xxx/xxx', {
  //     method: 'post',
  //     params: { type: 0 },
  //     baseURL: app['base_url']
  // })

  // const res = await useFetchData('/api/xxx/xxx', {
  //     method: 'post',
  //     params: { type: 0 },
  //     baseURL: app['base_url']
  // })

  // console.log(77711, res)

  // return res.data || []

  const method = getMethod(event).toUpperCase()
  let body
  if (method !== 'GET') body = await readRawBody(event)
  const res = await $fetch('/xxx/xxx/xxx', {
    method,
    baseURL: event.context.baseUrl,
    headers: event.context.headers,
    params: getQuery(event),
    body
  })
  return res || { userInfo: {} }
})
